package rpcserver

import "smartconn.cc/cubestruct/Msg"

// EeventNoticeFromService define
func (t *App) EeventNoticeFromService(msg *Msg.EventFromService, reply *Msg.EventFromServiceReply) error {
	if msg.Name == Msg.WifiEventName {
		if msg.Body["status"].(bool) == true {
			WifiOnEventList.Range(func(_, f interface{}) bool {
				go f.(func())()
				return true
			})
			reply.Name = Msg.WifiEventName
			reply.Body = make(map[string]interface{})
			reply.Body["status"] = true
		}

		if msg.Body["status"].(bool) == false {
			WifiOffEventList.Range(func(_, f interface{}) bool {
				go f.(func())()
				return true
			})
			reply.Name = Msg.WifiEventName
			reply.Body = make(map[string]interface{})
			reply.Body["status"] = true
		}
	}

	return nil
}
